#include<iostream>
using namespace std;
const int m = 3, n = 4;
int arr[m][n] = { {1,1,1,1},{1,1,1,1},{1,1,1,1} };
int sum[m][n];
int d[m + 1][n + 1];
void add(int x1, int y1, int x2, int y2, int v)
{
	d[x1][y1] += v;
	d[x1][y2 + 1] -= v;
	d[x2 + 1][y1] -= v;
	d[x2 + 1][y2 + 1] += v;
}
void pre_sum()
{
	sum[0][0] = d[0][0];
	for (int i = 1; i < m; i++)
	{
		sum[i][0] += d[i][0] + sum[i - 1][0];
	}
	for (int i = 1; i < n; i++)
	{
		sum[0][i] += d[0][i] + sum[0][i - 1];
	}
	for (int i = 1; i < m; i++)
	{
		for (int j = 1; j < n; j++)
		{
			sum[i][j] += d[i][j] + sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
		}
	}
}
int main()
{
	add(1, 1, 2, 2, 5);
	add(1, 2, 2, 3, 5);
	pre_sum();
	for (int i = 0; i < m; i++)
	{
		for (int j = 0; j < n; j++)
		{
			arr[i][j] += sum[i][j];
			cout << arr[i][j] << " ";
		}
		cout << endl;
	}
	return 0;
}